package windows
{
	import com.bit101.components.Window;
	import com.bit101.components.PushButton;
	import flash.events.MouseEvent;
	import baseitems.Base;
	import property.Padding;
	import property.ItemType;
	
	/**
	 * панелька инструментов
	 * @author yaempechenki@gmail.com
	 */
	public class ComponentsWindow extends Window
	{
		// кнопки

		public function ComponentsWindow()
		{
			title = "Components";
			hasMinimizeButton = true;
			width = 120;
			height = 260;
			var buttonNames:Vector.<String> = ItemType.allTypes;
			for (var i:int = 0; i < buttonNames.length; i++) 
			{
				var button:PushButton = new PushButton(this, 10, 10 + 36 * i, buttonNames[i], onComponentsClick);
				button.height = 26;
				button.tabIndex = i;
				button.enabled = i < buttonNames.length - 1; // дизейблим последнюю кнопку
			}
		}
		
		private function onComponentsClick(event:MouseEvent):void {
			// тестовое
			var type:String = ItemType.allTypes[event.target.tabIndex];
			/*if (type == ItemType.SPRITE && Controller.instance.getItems().length == 0 )
			{
				var item1:Base = Controller.instance.addObject(ItemType.NODE);
				item1.height = item1.width = 200;

				var item2:Base = Controller.instance.addObject(ItemType.NODE);
				item2.padding = new Padding(10,0,0,0);
				item2.selfParent = item1;
				
				Controller.instance.selectedObject = item1;
				
				return;
			}*/
			var item:Base = Controller.instance.addObject(type);
			Controller.instance.selectedObject = item;
		}
	}
}